import requests
from bs4 import BeautifulSoup


'''
爬取健康饮食文章分类列表
    1.文章跳转链接
    2.文章图片
    3.文章标题
    4.评论
    5.人气
'''
def diet_list(cid,page):
    url = "https://www.meishij.net/health.php?cid="+cid+"&sortby=update&page="+str(page)
    session = requests.session()
    response = session.get(url).text
    soup = BeautifulSoup(response,"html.parser")
    par = soup.find("div",class_='listtyle1_list clearfix')
    par_list = par.find_all('div','listtyle1')
    data = []
    for list in par_list:
        dict = {}
        dict["diet_href"] = list.find('a').get('href')
        dict["diet_name"] = list.find('a').get('title')
        dict["diet_img"] = list.find('img').get('src')
        dict["diet_comment"] = list.find('div',class_='d1').find_all('span')[0].text
        dict["diet_popularity"] = list.find('div', class_='d1').find_all('span')[1].text
        data.append(dict)
    return data



def HeathlyArticle(url):
    session = requests.session()
    response = session.get(url).text
    soup = BeautifulSoup(response, "html.parser")
    par = soup.find("div", class_="cp_body_left")
    title = par.find('div', class_='artical_title_w').find('h1').text
    measure = soup.find('div', class_='measure')
    data= {}
    data["title"] = title
    data["measure"] = str(measure)
    return data

if __name__ == '__main__':
    # diet_list("19","1")
    data  = HeathlyArticle("https://www.meishij.net/changshi/nianmoyingchouduohejiuqianhouyinshiyoujiangjiu.html")
    print(data)